package com.k.demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.k.demo.entity.ChangeStyle;
import com.k.demo.entity.ConstantTerm;
import com.k.demo.service.ChangeStyleService;

@Controller
@RequestMapping("/changestyle")
public class ChangeStyleController {
	
	@Autowired
	private ChangeStyleService changeStyleService;
	
	/**
	 * 返回所有变动形式
	 * url /changestyle/all
	 * @author shy
	 */
	@RequestMapping("/all")
	public Object all() {
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("ChangeStyleList", changeStyleService.getAll());
		
		return map;
	}
	
	/**
	 * 返回制定的常数
	 * url /changestyle/searchById
	 * @author shy
	 */
	@RequestMapping("/searchById")
	public Object getById(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("searchResult", changeStyleService.getById((int)map.get("point_change_id")));
		
		return rmap;
	}
	
	/**
	 * 根据输入的内容返回制定的常数
	 * url /changestyle/searchById
	 * @author shy
	 */
	@RequestMapping("/searchByContent")
	public Object getByContent(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("searchResult", changeStyleService.getByContent((String)map.get("point_change_conte")));
		
		return rmap;
	}
	
	/**
	 * 根据数组进行批量删除
	 * url /changestyle/deletegroup
	 * @author shy
	 */
	@RequestMapping("/deletegroup")
	public Object deleteCTs(@RequestBody String deleteGroup) {
		
		JSONObject jsonObject = JSON.parseObject(deleteGroup);
		
		List<Integer> deleteList = JSON.parseArray(jsonObject.getString("deleteList"), Integer.class);
		
		Map<String,Object> map = new HashMap<String, Object>();
		
		map.put("deleteGroupResult", changeStyleService.deleteByGroup(deleteList));
		
		return map;
	}
	
	/**
	 * 根据对象进行修改
	 * url /changestyle/modify
	 * @author shy
	 */
	@RequestMapping("/modify")
	public Object modifyChangeStyle(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("modifyResult", changeStyleService.modifyChangeStyle((ChangeStyle)map.get("changeStyle")));
		
		return rmap;
	}
	
	/**
	 * 根据对象添加
	 * url /changestyle/modify
	 * @author shy
	 */
	@RequestMapping("/add")
	public Object addChangeStyle(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("addResult", changeStyleService.addChangeStyle((ChangeStyle)map.get("changeStyle")));
		
		return rmap;
	}
	
	/**
	 * 关于变动形式的getall并分页显示
	 * url/changestyle/getallpage
	 * @author shy
	 */
	@RequestMapping("/getallpage")
	public Object getAllWithPage(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("searchByNameList", changeStyleService.getAllWithPage((int)map.get("pageNum"), (int)map.get("pageSize")));
		
		return rmap;
		
	}

	/**
	 * 关于变动形式的模糊查询并分页显示
	 * url/searchByContent
	 * @author shy
	 */
	@RequestMapping("/searchByContentWithPage")
	public Object searchCTByConstantTerm(@RequestBody Map<String,Object> map) {
		
		Map<String,Object> rmap = new HashMap<String, Object>();
		
		rmap.put("searchByNameList", changeStyleService.getByContentWithPage((int)map.get("pageNum"),(int)map.get("pageSize"),(String)map.get("point_change_conte")));
		
		return rmap;
		
	}
	

}
